var util = require('../../utils/util.js');
var api = require('../../config/api.js');

var app = getApp()
Page({
  data: {
    tag:'',
    keywrod: '',
    searchStatus: false,
    storeList: [],
    helpKeyword: [],
    historyKeyword: [],
    categoryFilter: false,
    currentSort: 'name',
    currentSortType: 'default',
    currentSortOrder: 'desc',
    filterCategory: [],
    defaultKeyword: {},
    hotKeyword: [],
    page: 1,
    limit: 20,
  },
  //事件处理函数
  closeSearch: function() {
    wx.navigateBack()
  },
  clearKeyword: function() {
    this.setData({
      keyword: '',
      searchStatus: false
    });
  },
  onLoad: function(options) {
    let tag = options.tag;
    this.setData({
      tag:tag,
      keyword:'',
      page: 1,
      storeList: []
    });

    let that = this;
    util.request(api.StoreList, {
      tag:that.data.tag,
      keyword: that.data.keyword,
      page: that.data.page,
      limit: that.data.limit,
      sort: that.data.currentSort,
      order: that.data.currentSortOrder
    }).then(function(res) {
      if (res.errno === 0) {
        that.setData({
          searchStatus: true,
          storeList: res.data.list
        });
      }
    });
  },
  getStoreList: function() {
    let that = this;
    util.request(api.StoreList, {
      tag:that.data.tag,
      keyword: that.data.keyword,
      page: that.data.page,
      limit: that.data.limit,
      sort: that.data.currentSort,
      order: that.data.currentSortOrder
    }).then(function(res) {
      if (res.errno === 0) {
        that.setData({
          searchStatus: true,
          storeList: res.data.list
        });
      }
    });
  }
})